package com.zhuiYun.project.api.handworkDiy.controller;

import com.alibaba.fastjson.JSONArray;
import com.zhuiYun.project.annotation.OptLog;
import com.zhuiYun.project.api.commodity.model.CommodityModel;
import com.zhuiYun.project.api.handworkDiy.entity.HandworkDiy;
import com.zhuiYun.project.api.handworkDiy.model.HandworkDiyModel;
import com.zhuiYun.project.api.handworkDiy.service.handworkService;
import com.zhuiYun.project.api.order.model.CommorderModel;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonConstants;
import com.zhuiYun.project.common.response.CommonResult;
import com.zhuiYun.project.util.pageUtil.PageRequest;
import com.zhuiYun.project.util.pageUtil.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/handwork")
@Api(tags = "diy商品管理")
@CrossOrigin
@Slf4j
public class handworkContorller {


    @Autowired
    handworkService handworkservice;

    /**
     * @Author 小江
     * @Description //TODO diy全查
     * @Date 13:28 2023/4/6
     **/
    @GetMapping("diyList")
    @ApiOperation(value = "diy管理的查询方法")
    @OptLog(modular = "diy管理", type = CommonConstants.ADD, describe = "查询方法")
    CommonResult diyList(PageRequest pageResult, String diyName ){
        PageResult pageResult1 =handworkservice.diyList(pageResult,diyName);
        log.info("diy查询用户信息分页");
        return CommonResult.ok(pageResult1);
    }
    /**
     * @Author 小江
     * @Description //TODO diy两表查询
     * @Date 9:37 2023/4/18
     **/
    @GetMapping("diysList")
    @ApiOperation(value = "diy管理的查询方法")
    @OptLog(modular = "diy管理", type = CommonConstants.ADD, describe = "查询方法")
    CommonResult diysList(PageRequest pageResult, String diyName ){
        PageResult pageResult1 =handworkservice.diysList(pageResult,diyName);
        log.info("diy查询用户信息分页");
        return CommonResult.ok(pageResult1);
    }

    /**
     * @Author 小江
     * @Description //TODO 查询下架diy商品
     * @Date 9:37 2023/4/18
     **/
    @GetMapping("regretDiy")
    @ApiOperation(value = "diy管理的查询方法")
    @OptLog(modular = "diy管理", type = CommonConstants.ADD, describe = "查询方法")
    CommonResult regretDiy(PageRequest pageResult, String diyName){
        PageResult pageResult1 =handworkservice.regretDiy(pageResult,diyName);
        log.info("diy查询用户信息分页");
        return CommonResult.ok(pageResult1);
    }

    /**
     * @Author 小江
     * @Description //TODO 查询回收站diy商品
     * @Date 9:37 2023/4/18
     **/
    @GetMapping("recycleDiy")
    @ApiOperation(value = "diy管理的查询方法")
    @OptLog(modular = "diy管理", type = CommonConstants.ADD, describe = "查询方法")
    CommonResult recycleDiy(PageRequest pageResult, String diyName){
        PageResult pageResult1 =handworkservice.recycleDiy(pageResult,diyName);
        log.info("diy查询用户信息分页");
        return CommonResult.ok(pageResult1);
    }

    /**
     * @Author 小江
     * @Description //TODO diy商品查询
     * @Date 8:42 2023/4/11
     **/
    @GetMapping("ditylcomlist")
    CommonResult ditylcomlist(HandworkDiyModel handworkDiyModel){
        CommonResult commonResult = handworkservice.ditylcomlist(handworkDiyModel);
        log.info("diy查询用户信息");
        return commonResult;
    }

    /**
     * @Author 小江
     * @Description //TODO 两表查询(diy信息和商品信息)
     * @Date 14:06 2023/4/10
     **/
    @GetMapping("commanddiylist")
    @ApiOperation(value = " diy信息和商品信息")
    @OptLog(modular = "diy信息和商品信息", type = CommonConstants.ADD, describe = "diy信息和商品信息")
    CommonResult commanddiylist(HandworkDiyModel handworkDiyModel) {
        log.info("两表查询diy和商品表");
        CommonResult commonResult = handworkservice.commanddiylist(handworkDiyModel);
        return commonResult;
    }

    /*/*
     * @Author 小江
     * @Description //TODO 添加diy
     * @Date 14:41 2023/4/6
     **/
    @PostMapping("/diyAdd")
    @ApiOperation(value = "diy管理的添加方法")
    @OptLog(modular = "diy管理", type = CommonConstants.ADD, describe = "添加方法")
    public CommonResult diyAdd(MultipartFile diyImageId1, MultipartFile[] diyDetailsImageId1, HandworkDiyModel handworkDiyModel, String JSONspecs) {
        int i = handworkservice.diyAdd(diyImageId1,diyDetailsImageId1, handworkDiyModel);

        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.error("添加失败");
        }
    }

    /**
     * @Author 小江
     * @Description //TODO diy管理修改
     * @Date 18:43 2023/4/11
     **/
    @PostMapping("/HandworkDiyUpdate")
    @ApiOperation(value = "商品管理的修改方法")
    @OptLog(modular = "商品修改", type = CommonConstants.ADD, describe = "修改商品")
    public CommonResult HandworkDiyUpdate(MultipartFile diyImageId1, MultipartFile[] diyDetailsImageId1, HandworkDiyModel handworkDiyModel){
        int i = handworkservice.CommodityUpdate(diyImageId1,diyDetailsImageId1, handworkDiyModel);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.error("修改失败");
        }
    }

    /**
     * @Author 小江
     * @Description //TODO 下架diy商品
     * @Date 9:39 2023/4/7
     **/
    @DeleteMapping("handworkDel")
    @ApiOperation(value = "diy管理的删除方法")
    @OptLog(modular = "diy管理", type = CommonConstants.ADD, describe = "删除方法")
    CommonResult handworkDel(Integer id){
        int i = handworkservice.handworkDel(id);
        log.info("删除diy商品");
        if (i > 0) {
            return CommonResult.ok();
        } else {
            return CommonResult.error();
        }
    }


    /**
     * @Author 小江
     * @Description //TODO 进入回收站
     * @Date 11:40 2023/4/18
     **/
    @DeleteMapping("recycleDel")
    @ApiOperation(value = "diy管理的删除方法")
    @OptLog(modular = "diy管理", type = CommonConstants.ADD, describe = "删除方法")
    CommonResult recycleDel(Integer id){
        int i = handworkservice.recycleDel(id);
        log.info("删除diy商品");
        if (i > 0) {
            return CommonResult.ok();
        } else {
            return CommonResult.error();
        }
    }





    /**
     * @Author 小江
     * @Description //TODO 上架diy商品
     * @Date 9:39 2023/4/7
     **/
    @DeleteMapping("redemptionDiy")
    @ApiOperation(value = "diy管理的删除方法")
    @OptLog(modular = "diy管理", type = CommonConstants.ADD, describe = "删除方法")
    CommonResult redemptionDiy(Integer id){
        int i = handworkservice.redemptionDiy(id);
        log.info("删除diy商品");
        if (i > 0) {
            return CommonResult.ok();
        } else {
            return CommonResult.error();
        }
    }

    /**
     * @Author 小江
     * @Description //TODO 彻底删除diy商品
     * @Date 11:40 2023/4/18
     **/
    @DeleteMapping("partDiy")
    @ApiOperation(value = "diy管理的删除方法")
    @OptLog(modular = "diy管理", type = CommonConstants.ADD, describe = "删除方法")
    CommonResult phoenixDiy(Integer id){
        int i = handworkservice.partDiy(id);
        log.info("删除diy商品");
        if (i > 0) {
            return CommonResult.ok();
        } else {
            return CommonResult.error();
        }
    }





}
